package com.mg.framework.kernel;

import android.app.Activity;
import android.os.Bundle;
import android.util.DisplayMetrics;
import android.view.KeyEvent;

import com.mg.game.GameScreen;

public class MG extends Activity {

	private MV mv = null;

	private int width = 0;
	private int height = 0;

	private void initGame() {
		DisplayMetrics metrics = new DisplayMetrics();
		this.getWindowManager().getDefaultDisplay().getMetrics(metrics);
		this.width = metrics.widthPixels;
		this.height = metrics.heightPixels;
		Assets.initAssets(this);
		Assets.loadingInitAssets();
		ScreenFactory.initScreenFactory(this.width, this.height);
		this.mv = new MV(this, ScreenFactory.newScreen("GameScreen",
				GameScreen.class));
		ScreenFactory.setMV(mv);
	}

	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		// 游戏设置为全屏，有动画效果
		// this.requestWindowFeature(Window.FEATURE_NO_TITLE);
		// getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
		// WindowManager.LayoutParams.FLAG_FULLSCREEN);

		initGame();
		setContentView(this.mv);
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
	}

	@Override
	protected void onPause() {
		super.onPause();
	}

	@Override
	protected void onResume() {
		super.onResume();
	}

	@Override
	protected void onStart() {
		super.onStart();
	}

	@Override
	protected void onStop() {
		super.onStop();
	}

	@Override
	public boolean onKeyDown(int keyCode, KeyEvent event) {
		if (keyCode == KeyEvent.KEYCODE_BACK) {
			this.finish();
		}
		return true;
	}

	@Override
	public void finish() {
		super.finish();
	}
}